package com.o2opuzi.lib.web;

import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.util.StringUtils;
import org.springframework.web.util.HtmlUtils;

import com.alibaba.fastjson.JSON;

public class SuperObject {
	
	public final Log log = LogFactory.getLog(getClass());
	
	public boolean isEmpty(Object str){
		return StringUtils.isEmpty(str);
	}
	
	public boolean notEmpty(Object str){
		return !isEmpty(str);
	}
	
	public int len(Object str){
		if(isEmpty(str)){
			return 0;
		}
		return str.toString().length();
	}
	
	public String str(Object str){
		return str.toString();
	}
	
	@SuppressWarnings("unchecked")
	public Map<String, Object> jsonDecode(String text){
		return JSON.parseObject(text, Map.class);
	}
	
	public String jsonEncode(Object object){
		return JSON.toJSONString(object);
	}
	
	public String htmlEncode(String html){
		return HtmlUtils.htmlEscape(html);
	}
	
	
	
}
